package com.jiashn.minio.controller;

import com.jiashn.minio.service.UploadMultipartFileService;
import com.jiashn.minio.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author: jiangjs
 * @description: 分片上传文件
 * @date: 2023/10/25 16:05
 **/
@RestController
@RequestMapping("/multipart")
public class UploadMultipartFileController {

    @Autowired
    private UploadMultipartFileService multipartFileService;

    @GetMapping("/create.do")
    public JsonResult<?> createMultipartUploadUrl(@RequestParam(value = "chunkNum",defaultValue = "0") Integer chunkNum,
                                                  @RequestParam("fileName") String fileName,
                                                  @RequestParam("contentType") String contentType){
       return multipartFileService.createMultipartUploadUrl(chunkNum,fileName,contentType);
    }
    @GetMapping("/complete.do")
    public JsonResult<?> completeMultipart(@RequestParam(value = "chunkNum",defaultValue = "0") Integer chunkNum,
                                           @RequestParam("fileName") String fileName,
                                           @RequestParam("contentType") String contentType,
                                           @RequestParam("uploadId") String uploadId,
                                           @RequestParam("fileMd5") String fileMd5){
       return multipartFileService.completeMultipart(chunkNum,fileName,contentType,uploadId,fileMd5);
    }
}
